From c867813646ca13e98747b3624e8c53e74f60b091 Mon Sep 17 00:00:00 2001 From: Sondre Lefsaker Date: Sun, 3 May 2015 01:11:46 +0200 Subject: [PATCH] Add more tests: - `build_with_args_to_one_of_multiple_binaries`, verify that only one bin gets built - `fails_with_args_to_all_binaries` - `build_with_args_to_one_of_multiple_tests`, same behavious as for the binaries - `build_foo_with_bar_dependency`, verify that bar dependency gets built and only foo gets compiled with args - `build_only_bar_dependency`, build the bar package, that foo depends, on with the extra args --- tests/test_cargo_rustc.rs | 171 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+) diff --git a/tests/test_cargo_rustc.rs b/tests/test_cargo_rustc.rs index 21cd75aa9..3729558c9 100644 --- a/tests/test_cargo_rustc.rs +++ b/tests/test_cargo_rustc.rs @@ -120,3 +120,174 @@ test!(fails_when_trying_to_build_main_and_lib_with_args { .with_status(101) .with_stderr("extra arguments to `rustc` can only be invoked for one target")); }); + +test!(build_with_args_to_one_of_multiple_binaries { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + "#) + .file("src/bin/foo.rs", r#" + fn main() {} + "#) + .file("src/bin/bar.rs", r#" + fn main() {} + "#) + .file("src/bin/baz.rs", r#" + fn main() {} + "#) + .file("src/lib.rs", r#" "#); + + assert_that(p.cargo_process("rustc").arg("-v").arg("--bin").arg("bar") + .arg("--").arg("-Z").arg("unstable-options"), + execs() + .with_status(0) + .with_stdout(format!("\ +{compiling} foo v0.0.1 ({url}) +{running} `rustc src{sep}lib.rs --crate-name foo --crate-type lib -g \ + --out-dir {dir}{sep}target{sep}debug [..]` +{running} `rustc src{sep}bin{sep}bar.rs --crate-name bar --crate-type bin -g \ + -Z unstable-options [..]` +", + compiling = COMPILING, running = RUNNING, sep = SEP, + dir = p.root().display(), url = p.url()))); +}); + +test!(fails_with_args_to_all_binaries { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + "#) + .file("src/bin/foo.rs", r#" + fn main() {} + "#) + .file("src/bin/bar.rs", r#" + fn main() {} + "#) + .file("src/bin/baz.rs", r#" + fn main() {} + "#) + .file("src/lib.rs", r#" "#); + + assert_that(p.cargo_process("rustc").arg("-v") + .arg("--").arg("-Z").arg("unstable-options"), + execs() + .with_status(101) + .with_stderr("extra arguments to `rustc` can only be invoked for one target")); +}); + +test!(build_with_args_to_one_of_multiple_tests { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + "#) + .file("tests/foo.rs", r#" "#) + .file("tests/bar.rs", r#" "#) + .file("tests/baz.rs", r#" "#) + .file("src/lib.rs", r#" "#); + + assert_that(p.cargo_process("rustc").arg("-v").arg("--test").arg("bar") + .arg("--").arg("-Z").arg("unstable-options"), + execs() + .with_status(0) + .with_stdout(format!("\ +{compiling} foo v0.0.1 ({url}) +{running} `rustc src{sep}lib.rs --crate-name foo --crate-type lib -g \ + --out-dir {dir}{sep}target{sep}debug [..]` +{running} `rustc tests{sep}bar.rs --crate-name bar --crate-type bin -g \ + -Z unstable-options [..]--test[..]` +", + compiling = COMPILING, running = RUNNING, sep = SEP, + dir = p.root().display(), url = p.url()))); +}); + +test!(build_foo_with_bar_dependency { + let foo = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [dependencies.bar] + path = "../bar" + "#) + .file("src/main.rs", r#" + extern crate bar; + fn main() { + bar::baz() + } + "#); + let bar = project("bar") + .file("Cargo.toml", r#" + [package] + name = "bar" + version = "0.1.0" + authors = [] + "#) + .file("src/lib.rs", r#" + pub fn baz() {} + "#); + bar.build(); + + assert_that(foo.cargo_process("rustc").arg("-v").arg("--").arg("-Z").arg("unstable-options"), + execs() + .with_status(0) + .with_stdout(format!("\ +{compiling} bar v0.1.0 ({url}) +{running} `[..] -g -C [..]` +{compiling} foo v0.0.1 ({url}) +{running} `[..] -g -Z unstable-options [..]` +", + compiling = COMPILING, running = RUNNING, + url = foo.url()))); +}); + +test!(build_only_bar_dependency { + let foo = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [dependencies.bar] + path = "../bar" + "#) + .file("src/main.rs", r#" + extern crate bar; + fn main() { + bar::baz() + } + "#); + let bar = project("bar") + .file("Cargo.toml", r#" + [package] + name = "bar" + version = "0.1.0" + authors = [] + "#) + .file("src/lib.rs", r#" + pub fn baz() {} + "#); + bar.build(); + + assert_that(foo.cargo_process("rustc").arg("-v").arg("-p").arg("bar") + .arg("--").arg("-Z").arg("unstable-options"), + execs() + .with_status(0) + .with_stdout(format!("\ +{compiling} bar v0.1.0 ({url}) +{running} `[..]--crate-name bar --crate-type lib [..] -Z unstable-options [..]` +", + compiling = COMPILING, running = RUNNING, + url = foo.url()))); +}); -- 2.30.2